package com.open.thinks.todo.system.domain;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "users")
public class User {
	@Id
	@Column
	private String user_id;
	@Column
	@NotBlank(message = "user name can not be null")
	private String user_name;
	@Column
	@NotBlank(message = "user password can not be null")
	private String user_password;
	@Column
	private String email;

	@OneToMany(mappedBy = "createby")
	private List<Task> ownedTasks;
	@OneToMany(mappedBy = "assignee")
	private List<Task> assignedTasks;
	@OneToMany(mappedBy = "updateby")
	private List<Task> updatedTasks;

	public String getUser_id() {
		return user_id;
	}

	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}

	public String getUser_password() {
		return user_password;
	}

	public void setUser_password(String user_password) {
		this.user_password = user_password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Task> getOwnedTasks() {
		return ownedTasks;
	}

	public void setOwnedTasks(List<Task> ownedTasks) {
		this.ownedTasks = ownedTasks;
	}

	public List<Task> getAssignedTasks() {
		return assignedTasks;
	}

	public void setAssignedTasks(List<Task> assignedTasks) {
		this.assignedTasks = assignedTasks;
	}

	public List<Task> getUpdatedTasks() {
		return updatedTasks;
	}

	public void setUpdatedTasks(List<Task> updatedTasks) {
		this.updatedTasks = updatedTasks;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((user_id == null) ? 0 : user_id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (user_id == null) {
			if (other.user_id != null)
				return false;
		} else if (!user_id.equals(other.user_id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return getUser_name();
	}

}
